bitkeeper revision 1.1159.222.1 (41ebdd9btvi-aV_bkwfCgKSenC9XbQ)
authorcl349@arcadians.cl.cam.ac.uk <cl349@arcadians.cl.cam.ac.uk>
Mon, 17 Jan 2005 15:45:31 +0000 (15:45 +0000)
committercl349@arcadians.cl.cam.ac.uk <cl349@arcadians.cl.cam.ac.uk>
Mon, 17 Jan 2005 15:45:31 +0000 (15:45 +0000)
Add an optional parameter (vcpus) to the xc_linux_build function replacing
the getenv() previously used and removing the requirement of using maxcpus
kernel parameter to limit the number of virtual cpus a guest uses.  The value
can now be controlled in the domain configuration files.

The default value of 1 is set in XenDomainInfo.py but is overridden by
parsing the config value.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
tools/examples/xmexample1
tools/examples/xmexample2
tools/libxc/xc.h
tools/libxc/xc_linux_build.c
tools/python/xen/lowlevel/xc/xc.c
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xm/create.py

index cdf4b6c82457fc8c2c253383614346d79da54157..b7b7dd437c0fbd3176be27cfe936ba773b6ba359 100644 (file)
@@ -25,6 +25,9 @@ name = "ExampleDomain"
 # Which CPU to start domain on? 
 #cpu = -1   # leave to Xen to pick
 
+# Number of Virtual CPUS to use, default is 1
+#vcpus = 1
+
 #----------------------------------------------------------------------------
 # Define network interfaces.
 
index 61479ca5f0693ed08768e87e259b7ceae42f02bb..07a80db3661c76cb607550cb32bd1ff950161233 100644 (file)
@@ -55,6 +55,10 @@ name = "VM%d" % vmid
 #cpu = -1   # leave to Xen to pick
 cpu = vmid  # set based on vmid (mod number of CPUs)
 
+# Number of Virtual CPUS to use, default is 1
+#vcpus = 1
+vcpus = 4 # make your domain a 4-way
+
 #----------------------------------------------------------------------------
 # Define network interfaces.
 
index 8114faafb2e654f83010d99f31d0db96da72a9ad..40346571b6a85a84d2e24332771e4fbe78851b2b 100644 (file)
@@ -97,7 +97,8 @@ int xc_linux_build(int xc_handle,
                    const char *ramdisk_name,
                    const char *cmdline,
                    unsigned int control_evtchn,
-                   unsigned long flags);
+                   unsigned long flags,
+                   unsigned int vcpus);
 
 int
 xc_plan9_build (int xc_handle,
index 2540819d5fd7bbbb90a413f185eb06e695f45894..9c684fb1436ac49f3aab6636b888920bec716dbb 100644 (file)
@@ -97,7 +97,8 @@ static int setup_guestos(int xc_handle,
                          const char *cmdline,
                          unsigned long shared_info_frame,
                          unsigned int control_evtchn,
-                         unsigned long flags)
+                         unsigned long flags,
+                         unsigned int vcpus)
 {
     l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
     l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
@@ -127,8 +128,6 @@ static int setup_guestos(int xc_handle,
     unsigned long vpt_end;
     unsigned long v_end;
 
-    char *n_vcpus;
-
     memset(&dsi, 0, sizeof(struct domain_setup_info));
 
     rc = parseelfimage(image, image_size, &dsi);
@@ -337,11 +336,10 @@ static int setup_guestos(int xc_handle,
     /* Mask all upcalls... */
     for ( i = 0; i < MAX_VIRT_CPUS; i++ )
         shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
-    n_vcpus = getenv("XEN_VCPUS");
-    if ( n_vcpus )
-       shared_info->n_vcpu = atoi(n_vcpus);
-    else
-       shared_info->n_vcpu = 1;
+
+    shared_info->n_vcpu = vcpus;
+    printf(" VCPUS:         %d\n", shared_info->n_vcpu);
+
     munmap(shared_info, PAGE_SIZE);
 
     /* Send the page update requests down to the hypervisor. */
@@ -433,7 +431,8 @@ int xc_linux_build(int xc_handle,
                    const char *ramdisk_name,
                    const char *cmdline,
                    unsigned int control_evtchn,
-                   unsigned long flags)
+                   unsigned long flags,
+                   unsigned int vcpus)
 {
     dom0_op_t launch_op, op;
     int initrd_fd = -1;
@@ -498,7 +497,7 @@ int xc_linux_build(int xc_handle,
                        &vstartinfo_start, &vkern_entry,
                        ctxt, cmdline,
                        op.u.getdomaininfo.shared_info_frame,
-                       control_evtchn, flags) < 0 )
+                       control_evtchn, flags, vcpus) < 0 )
     {
         ERROR("Error constructing guest OS");
         goto error_out;
index b4ad35b9c04c0a87f9726e5f86aac461f0f3fb1b..6fb510111fb00f5c64827ebcc5551488e60f7348 100644 (file)
@@ -348,19 +348,19 @@ static PyObject *pyxc_linux_build(PyObject *self,
 
     u32   dom;
     char *image, *ramdisk = NULL, *cmdline = "";
-    int   control_evtchn, flags = 0;
+    int   control_evtchn, flags = 0, vcpus = 1;
 
     static char *kwd_list[] = { "dom", "control_evtchn", 
-                                "image", "ramdisk", "cmdline", "flags",
+                                "image", "ramdisk", "cmdline", "flags", "vcpus",
                                 NULL };
 
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|ssi", kwd_list, 
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|ssii", kwd_list, 
                                       &dom, &control_evtchn, 
-                                      &image, &ramdisk, &cmdline, &flags) )
+                                      &image, &ramdisk, &cmdline, &flags, &vcpus) )
         return NULL;
 
     if ( xc_linux_build(xc->xc_handle, dom, image,
-                        ramdisk, cmdline, control_evtchn, flags) != 0 )
+                        ramdisk, cmdline, control_evtchn, flags, vcpus) != 0 )
         return PyErr_SetFromErrno(xc_error);
     
     Py_INCREF(zero);
@@ -1023,6 +1023,7 @@ static PyMethodDef pyxc_methods[] = {
       " image   [str]:      Name of kernel image file. May be gzipped.\n"
       " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
       " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
+      " vcpus   [int, 1]:   Number of Virtual CPUS in domain.\n\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
     { "vmx_build", 
index c92bdf08bcac5a46823de3ed2b4a6b2685050043..83ae739c24c60702bf7060b9ef97aa881969e285 100644 (file)
@@ -321,6 +321,7 @@ class XendDomainInfo:
         self.console_port = None
         self.savedinfo = None
         self.is_vmx = 0
+        self.vcpus = 1
 
     def setdom(self, dom):
         """Set the domain id.
@@ -448,6 +449,11 @@ class XendDomainInfo:
             cpu = sxp.child_value(config, 'cpu')
             if self.recreate and self.dom and cpu is not None:
                 xc.domain_pincpu(self.dom, int(cpu))
+            try:
+                image = sxp.child_value(self.config, 'image')
+                self.vcpus = int(sxp.child_value(image, 'vcpus'))
+            except:
+                raise VmError('invalid vcpus value')
 
             self.init_domain()
             self.configure_console()
@@ -746,12 +752,14 @@ class XendDomainInfo:
                        ramdisk        = ramdisk,
                        flags          = flags)
        else:
+               log.warning('building dom with %d vcpus', self.vcpus)
                err = buildfn(dom            = dom,
                                image          = kernel,
                        control_evtchn = self.console.getRemotePort(),
                        cmdline        = cmdline,
                        ramdisk        = ramdisk,
-                       flags          = flags)
+                       flags          = flags,
+                       vcpus          = self.vcpus)
         if err != 0:
             raise VmError('Building domain failed: type=%s dom=%d err=%d'
                           % (ostype, dom, err))
@@ -1280,6 +1288,7 @@ add_config_handler('console',    vm_field_ignore)
 add_config_handler('image',      vm_field_ignore)
 add_config_handler('device',     vm_field_ignore)
 add_config_handler('backend',    vm_field_ignore)
+add_config_handler('vcpus',      vm_field_ignore)
 
 # Register other config handlers.
 add_config_handler('maxmem',     vm_field_maxmem)
index 633888a6435b694a4b6ad8bf1f2226a73662a537..73be2e039e4d86b479849b5ceb262eb48f785a50 100644 (file)
@@ -109,6 +109,10 @@ gopts.var('cpu', val='CPU',
           fn=set_int, default=None,
           use="CPU to run the domain on.")
 
+gopts.var('vcpus', val='VCPUS',
+          fn=set_int, default=1,
+          use="# of Virtual CPUS in domain.")
+
 gopts.var('cpu_weight', val='WEIGHT',
           fn=set_float, default=None,
           use="""Set the new domain's cpu weight.
@@ -245,7 +249,10 @@ def configure_image(config, vals):
         config_image.append(['root', cmdline_root])
     if vals.extra:
         config_image.append(['args', vals.extra])
+    if vals.vcpus:
+        config_image.append(['vcpus', vals.vcpus])
     config.append(['image', config_image ])
+
     
 def configure_disks(config_devs, vals):
     """Create the config for disks (virtual block devices).